import java.util.Arrays;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-10-13
 * Time: 13:35
 */
public class Test {

    public static void orderArray(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            //arr[i] = i;
            arr[i] = arr.length-i;//逆序
        }
    }
    public static void disorderArray(int[] arr) {
        Random random = new Random();
        for (int i = 0;i < arr.length;i++) {
            arr[i] = random.nextInt(10_0000);
        }
    }
    public static void insertTest(int[] arr) {
        arr = Arrays.copyOf(arr,arr.length);
        long startTime = System.currentTimeMillis();
        Sort.insertSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("直接插入排序耗时：" + (endTime-startTime));
    }
    public static void shellTest(int[] arr) {
        arr = Arrays.copyOf(arr,arr.length);
        long startTime = System.currentTimeMillis();
        Sort.shellSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序耗时：" + (endTime-startTime));
    }
    public static void selectSortTest(int[] arr) {
        arr = Arrays.copyOf(arr,arr.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort2(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("直接选择排序耗时：" + (endTime - startTime));
    }
    public static void heapSort(int[] arr) {
        arr = Arrays.copyOf(arr,arr.length);
        long startTime = System.currentTimeMillis();
        Sort.heapSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序耗时：" + (endTime - startTime));
    }

    public static void bubbleSortTest(int[] arr) {
        arr = Arrays.copyOf(arr,arr.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("冒泡排序耗时：" + (endTime - startTime));
    }
    public static void  quickSortTest(int[] arr) {
        arr = Arrays.copyOf(arr,arr.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序耗时：" + (endTime-startTime));
    }
    public static void  mergeSortTest(int[] arr) {
        arr = Arrays.copyOf(arr,arr.length);
        long startTime = System.currentTimeMillis();
        Sort.mergeSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("归并排序耗时：" + (endTime-startTime));
    }
    public static void countSortTest(int[] arr) {
        arr = Arrays.copyOf(arr,arr.length);
        long startTime = System.currentTimeMillis();
        Sort.countSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("计数排序耗时：" + (endTime-startTime));
    }
    public static void main(String[] args) {
        //randomTest();
        simpleTest();
    }
    public static void simpleTest() {
        int[] arr = {93,95,99,91,94,90,100,92,97,89,91,99,94,97,94,95,93};
        System.out.println(Arrays.toString(arr));
        Sort sort = new Sort();
        sort.mergeSort(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void randomTest() {
        int[] arr = new int[3_0000];
        //disorderArray(arr);
        orderArray(arr);
        insertTest(arr);
        shellTest(arr);
        //selectSortTest(arr);
        heapSort(arr);
        //bubbleSortTest(arr);
        quickSortTest(arr);//当排序越有序，数据量越大，递归的次数越多，会造成栈溢出StackOverflowError
        countSortTest(arr);
    }
}
